<?php
/**
 * Created by PhpStorm.
 * FileName: OrderReviewModel.class.php
 * User: Administrator
 * Date: 2018/12/27
 * Time: 13:40
 */

namespace Admin\Model;
use Think\Model\RelationModel;

class OrderReviewModel extends RelationModel {

    protected  $tableName = 'order_review';

    protected $_link = array(
        'user'=>array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Admin/User',
            'foreign_key' => 'user_id',
            'mapping_key' => 'id'
        )
    );

    public function add($data) {
        $data['add_time'] = time();
        return parent::add($data);
    }

    public function getList($where=array(),$pageSize=15,$curPage=false,$order='id desc') {
        $data = array();
        $count = $this->where($where)->count();
        if ($curPage !== false) {
            $curPage = ($curPage > 0) ? $curPage : 1;
            $firstRow = ($curPage-1)*$pageSize;
        } else {
            $pageInfo = getPage($count,$pageSize);
            $firstRow = $pageInfo->firstRow;
        }
        $dataList = $this->relation(true)->where($where)->order($order)->limit($firstRow,$pageSize)->select();
        $data['list'] = $dataList;
        $data['pageInfo'] = $pageInfo;
        $data['nowPage'] = ($curPage !== false) ? $curPage : ($pageInfo->nowPage ? $pageInfo->nowPage : 0);
        $data['page'] = $pageInfo ? $pageInfo->show() : '';
        $data['pageSize'] = $pageSize;
        return $data;
    }

}